<?php
class YWSLanguage {
    public static $_default = 1;
    public static $_defaulttxt = 'Tiếng Việt';
    public static $_list = array(1,2);
    public static $_listtxt = array('Tiếng Việt', 'Tiếng Anh');
    
    public static function setLanguage() {
        // Only set language when logged in
        if (isset($_SESSION[YWSAuthentication::$_session])) {
            if (!isset($_SESSION[YWSAuthentication::$_session]['lang']))
                    $_SESSION[YWSAuthentication::$_session]['lang'] = YWSLanguage::$_default;
        }
    }
    
    public static function switchLanguage($newlang) {
        $position = in_array($newlang, YWSLanguage::$_list);        
        if ($position)
            $_SESSION[YWSAuthentication::$_session]['lang'] = $newlang;         
    }
    
    public static function getLanguage() {
        if (isset($_SESSION[YWSAuthentication::$_session])) return $_SESSION[YWSAuthentication::$_session]['lang'];
        else return YWSLanguage::$_default;
    }
    
    public static function getLanguageText() {
        if (isset($_SESSION[YWSAuthentication::$_session])) {            
            $position = array_search($_SESSION[YWSAuthentication::$_session]['lang'], YWSLanguage::$_list);
            return YWSLanguage::$_listtxt[$position];
        }
        else return YWSLanguage::$_defaulttxt;
    }
}
?>
